package com.jd.basic.service.impl;

import com.jd.basic.mapper.BaseMapper;
import com.jd.basic.query.BaseQuery;
import com.jd.basic.service.IBaseService;
import com.jd.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        Integer totals = baseMapper.queryAll(baseQuery);
        if (totals==0){
            return new PageList<>();
        }
        // 查询当前分页数据
        List<T> data = baseMapper.queryData(baseQuery);
        return new PageList<>(data,totals);

    }
    //批量删除
    @Override
    public void patchRemove(List<Long> ids) {
        baseMapper.patchRemove(ids);
    }
    
}
